import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    func checkPingToBaidu(completion: @escaping (Bool) -> Void) {
        guard let url = URL(string: "https://www.baidu.com") else {
            completion(false)
            return
        }
        
        let task = URLSession.shared.dataTask(with: url) { _, response, error in
            if response is HTTPURLResponse {
                // 只要收到响应就认为可以连通，不关心具体状态码
                completion(true)
            } else {
                completion(false)
            }
        }
        
        task.resume()
    }
}

